﻿using System.Reflection;
using CommonFramework.Log;
using CommonFramework.Time;
using Net.Proto;

namespace Net.Server
{
    public static class NetPacketHandler
    {
        public static void OnNetPacket(NetSession client, NetPacket packet)
        {
            string name= packet.GetType().Name;
            MethodInfo method= typeof(NetPacketHandler).GetMethod($"On{name}");
            method?.Invoke(null, new object[] {client,packet});
        }

        public static void OnNetPacketPing(NetSession client, NetPacketPing packet)
        {
            LogUtil.Log("receive ping from "+client.Socket.RemoteEndPoint);
            client.LastHeartPingTime = TimeUtil.NowTimestampSeconds();
            //回复pong
            client.Send(new NetPacketPong());
        }
    }
}